<template>
  <div class="login-page">
    <video
      src="../../assets/login/loginbg.mp4"
      muted
      autoplay
      loop
      class="video"
    ></video>
    <div class="login-box">
      <div class="login-logo">
        <img src="../../assets/login/logo.png" alt="" />
      </div>
      <el-form
        :model="loginForm"
        :rules="rules"
        ref="loginForm"
        class="demo-ruleForm"
      >
        <el-form-item prop="account">
          <el-input
            type="account"
            placeholder="账号"
            v-model="loginForm.account"
            autocomplete="off"
          >
            <svg-icon slot="prefix" icon-class="user" class="login-icon"
          /></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            type="password"
            placeholder="密码"
            show-password
            v-model="loginForm.password"
            autocomplete="off"
            ><svg-icon slot="prefix" icon-class="password" class="login-icon"
          /></el-input>
        </el-form-item>
        <el-form-item prop="key">
          <el-input
            placeholder="验证码"
            v-model="loginForm.code"
            style="height: 54px"
          >
            <i slot="prefix" class="el-icon-s-claim login-icon code" />
            <el-image
              slot="suffix"
              style="width: 110px; height: 50px; margin-right: -4px; margin-top:1px"
              :src="`https://slwl-geteway.itheima.net/manager/captcha?key=${loginForm.key}`"
              @click="getNewCode"
            ></el-image>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            class="login-btn"
            type="primary"
            @click="loginFn('ruleForm')"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import nanoid from "@/api/getRandom";
export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        account: "shenlingadmin",
        password: "123456",
        key:'',
        code:'',
        bindAccount:'',
        bindPassword:'',
        signAccount:'',
        signPassword:'',
        tenant:'0000'
      },
      url: "",
      imageSrc: "",
      rules: {
        account: [{ required: true, message: "账号不得为空", trigger: "blur" }],
        password: [
          { required: true, message: "密码不得为空", trigger: "blur" },
        ],
        key: [{ required: true, message: "验证码不得为空", trigger: "blur" }],
      },
      loading: false,
      passwordType: "password",
    };
  },
  created() {
    this.loginForm.key = nanoid();
  },
  methods: {
    getNewCode(){
      this.loginForm.key = nanoid();
    },
    async loginFn(){
      await this.$refs.loginForm.validate()
      await this.$store.dispatch('user/login', this.loginForm)
      this.$message.success('登录成功')
      this.$router.push('/')
    }
  },
};
</script>

<style lang="scss">
.login-page {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  .video {
    width: 100%;
    height: 100%;
    object-fit: fill;
  }
  .login-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 450px;
    height: 467px;
    padding: 30px 40px;
    background-color: #fff;
    border-radius: 10px;

    .login-icon {
      color: #999999;
      margin-left: 13px;
      margin-top: 18px;
      line-height: 50px;
      font-size: 16px;
    }
    .code {
      margin-top: 0;
    }
    .el-input__inner {
      // border: none;
      height: 52px;
      padding-left: 45px;
    }

    .login-btn {
      width: 100%;
      height: 54px;
      background: #e15536;
      border: none;
      font-size: 18px;
      font-weight: 700;
      opacity: 0.91;
      border-radius: 8px;
      color: #fff;
      text-shadow: 0 7px 22px #cfcfcf;
      margin-top: 20px;
    }

    .login-logo {
      width: 195px;
      height: 54px;
      margin: 0 auto;
      margin-bottom: 35px;
      img {
        width: 195px;
        height: 54px;
      }
    }
  }
}
</style>
